
public class Main {
	
	private static int IP1=0;
	private static int IP2=0;
	private static int IP3=0;

	private static int I1=0;
	private static int I2=0;
	private static int I3=0;

	private static int x = 0;
	private static boolean ifstatement;
	
	public static void main(String[] args) {
		int[] permut = new int[9];
		do{
			perform(permut);
			IP1=0;
			IP2=0;
			IP3=0;
			x=0;
		
		}while(advance(permut));
	}

	private static void perform(int[] permut) {
		for(int i=0; i < permut.length; i++) {
			switch(permut[i]){
			case 0:
				Process1();
				break;
			case 1:
				Process2();
				break;
			case 2:
				Process3();
				break;
			default:
				System.out.println("error");
			}
		}
	}

	private static boolean advance(int[] array) {
		boolean cont= true;
		int i=0;
		int tmp;
		while(cont && i<array.length) {
			tmp=array[i];
			
			array[i]=(array[i]+1)%3;
			if(tmp < 2) return true;
			i++;
		}
		if(i == array.length && array[i-1] == 0) return false;
		return true;
	}
	public static void Process1()
	{
		switch(IP1){
		case 0:
			ifstatement=(x==0);
			break;
		case 1:
			if(ifstatement)
				x=1;
			else
				x=0;
			break;
		default: 
			break;
		}
		IP1++;
	}
	
	public static void Process2()
	{

		switch(IP2){
		case 0:
			I2=x;
			break;
			
		case 1:
			I2=x+I2+2;
			break;
		case 2:
			x=I2;
			break;
		default: 
			break;
		}
		IP2++;
	}
	
	public static void Process3()
	{

		switch(IP3){
		case 0:
			I3=x+1;
			break;
		case 1:
			x=I3;
			break;
		case 2:
			System.out.println(x+"\n");
			break;
		default: 
			break;
		}
		IP3++;
	}
	
	
}
